﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;

namespace Zero.UControl.Component
{
    public class MessageHost : ItemsControl
    {
        public string Token
        {
            get { return (string)GetValue(TokenProperty); }
            set { SetValue(TokenProperty, value); }
        }

        public static readonly DependencyProperty TokenProperty = 
            DependencyProperty.Register("Token", typeof(string), typeof(MessageHost), new PropertyMetadata(OnTokenChanged));

        private static void OnTokenChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            if (d is MessageHost host)
            {
                var token = e.NewValue.ToString();
                if (MessageManage.MessageHosts.ContainsKey(token))
                {
                    MessageManage.MessageHosts.Remove(token);
                }
                MessageManage.MessageHosts.Add(token, host);
            }
        }

        protected override bool IsItemItsOwnContainerOverride(object item)
        {
            return item is Message;
        }

        protected override DependencyObject GetContainerForItemOverride()
        {
            return new Message();
        }
    }
}
